package com.mcflies.activity.handler;

import java.util.ArrayList;
import java.util.List;

import com.mcflies.activity.welcome.R;
import com.mcflies.bean.ListViewBean;
import com.mcflies.commons.CommonsUtil;
import com.mcflies.commons.ListViewBaseAdapter;
import com.mcflies.commons.McfliesConstant;

import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-31
 * @comment:Handler学习主界面
 */
public class HandlerMainActivity extends Activity implements
		OnItemClickListener {
	private ListView listViewMian_LV;
	private TextView listViewMain_TV;
	private ListViewBaseAdapter adapter;
	private List<ListViewBean> beanList = new ArrayList<ListViewBean>();
	private String[] hanlderMainArray;
	private AssetManager assetManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listview_main);
		initWidget();
		initData();
		listViewMian_LV.setAdapter(adapter);
		listViewMian_LV.setOnItemClickListener(this);
	}

	private void initWidget() {
		listViewMian_LV = (ListView) findViewById(R.id.listViewMian_LV);
		listViewMain_TV = (TextView) findViewById(R.id.listViewMain_TV);
		listViewMain_TV.setText("Handler学习目录");
	}

	private void initData() {
		hanlderMainArray = getResources().getStringArray(
				R.array.hanlderMainArray);
		assetManager = getAssets();
		beanList = CommonsUtil.getListViewData(hanlderMainArray, assetManager,
				"listView");
		adapter = new ListViewBaseAdapter(this, beanList);
	}

	@Override
	public void onItemClick(AdapterView<?> adapter, View view, int position,
			long id) {
		try {
			Intent intent = new Intent(HandlerMainActivity.this,
					Class.forName(beanList.get(position).getIntent()));
			startActivity(intent);
		} catch (Exception e) {
			Log.i(McfliesConstant.MCFLIES_EXCEPTION_INFO_FLAG, e.getMessage());
		}
	}
}
